package blackstar.plugin.monitor.reporter;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Ray (ayufox@gmail.com)
 */
public class ListResultReporter implements ResultReporter
{
	private final static Log LOGGER = LogFactory
			.getLog(ListResultReporter.class);

	private boolean isAndMode = true;
	private List<ResultReporter> list = new ArrayList<ResultReporter>();

	public ListResultReporter()
	{
		this(true);
	}

	public ListResultReporter(boolean isAndMode)
	{
		this.isAndMode = isAndMode;
	}

	public void addResultReporter(ResultReporter reporter)
	{
		this.list.add(reporter);
	}

	public void report(ReportData data)
	{
		for (ResultReporter reporter : list)
		{
			if (isAndMode)
			{
				reporter.report(data);
			} else
			{
				try
				{
					reporter.report(data);

					return;
				} catch (Exception e)
				{
					LOGGER.error("Error When Report[" + reporter + "]", e);
				}
			}
		}
	}
}
